//ok
namespace hjc {

	export class Drag extends eui.Component {

		protected $offsetX: number;
		protected $offsetY: number;

		constructor() {
			super();
			this._init();
		}

		protected _init(): void {
			this.addEventListener(egret.TouchEvent.TOUCH_BEGIN, this._onTouchBegin, this);
		}

		protected createChildren() {
			super.createChildren();
			this._created();
		}
		protected _created(): void { }

		protected _onTouchBegin(e: egret.TouchEvent): void {
			this.$offsetX = e.stageX - this.x;
			this.$offsetY = e.stageY - this.y;
			this.stage.addEventListener(egret.TouchEvent.TOUCH_MOVE, this._onTouchMove, this);
			this.stage.addEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEnd, this);
		}

		protected _onTouchMove(e: egret.TouchEvent) {
			this.x = e.stageX - this.$offsetX;
			this.y = e.stageY - this.$offsetY;
		}

		protected _onTouchEnd(e: egret.TouchEvent) {
			let stage = e.currentTarget;
			stage.removeEventListener(egret.TouchEvent.TOUCH_MOVE, this._onTouchMove, this);
			stage.removeEventListener(egret.TouchEvent.TOUCH_END, this._onTouchEnd, this);
		}
	}
}